<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('考核细则详情')" />
    <style>
        .dangnei-content {
            padding: 20px;
            background: #fff;
            border-radius: 4px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }
        .dangnei-title {
            font-size: 24px;
            font-weight: bold;
            text-align: center;
            margin-bottom: 20px;
            color: #c52222;
            border-bottom: 2px solid #c52222;
            padding-bottom: 15px;
        }
        .dangnei-meta {
            text-align: center;
            margin-bottom: 30px;
            color: #666;
            font-size: 14px;
        }
        .dangnei-text {
            line-height: 1.8;
            font-size: 16px;
            color: #333;
        }
        .dangnei-pdf, .dangnei-image {
            text-align: center;
            margin: 20px 0;
        }
        .dangnei-pdf iframe {
            width: 100%;
            height: 600px;
            border: 1px solid #ddd;
        }
        .dangnei-image img {
            max-width: 100%;
            height: auto;
            border: 1px solid #ddd;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        .no-content {
            text-align: center;
            padding: 50px;
            color: #999;
            font-size: 18px;
        }
        .pdf-preview-fallback {
            padding: 20px;
            background: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 4px;
            margin: 20px 0;
        }
        .pdf-preview-fallback a {
            color: #007bff;
            text-decoration: none;
        }
        .pdf-preview-fallback a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="dangnei-content">
                <div class="dangnei-title" th:text="${commonCms.title}">细则标题</div>
                <div class="dangnei-meta">
                    <span>创建时间：<span th:text="${#dates.format(commonCms.createTime, 'yyyy-MM-dd HH:mm:ss')}">2023-01-01 12:00:00</span></span>
                    <span style="margin-left: 30px;">更新时间：<span th:text="${#dates.format(commonCms.updateTime, 'yyyy-MM-dd HH:mm:ss')}">2023-01-01 12:00:00</span></span>
                </div>

                <!-- 文字内容 -->
                <div class="dangnei-text" th:if="${commonCms.contentType == 'text' and !#strings.isEmpty(commonCms.content)}" th:utext="${commonCms.content}">
                    制度内容
                </div>

                <!-- PDF内容 -->
                <div class="dangnei-pdf" th:if="${commonCms.contentType == 'pdf' and !#strings.isEmpty(commonCms.filePath)}">
                    <iframe th:src="@{${commonCms.filePath}}" frameborder="0"></iframe>
                    <!-- 添加备用方案，如果iframe无法加载则提供下载链接 -->
                    <div class="pdf-preview-fallback">
                        <p>如果PDF无法正常显示，请<a th:href="@{${commonCms.filePath}}" target="_blank">点击此处下载PDF文件</a>进行查看。</p>
                    </div>
                </div>

                <!-- 图片内容 -->
                <div class="dangnei-image" th:if="${commonCms.contentType == 'image' and !#strings.isEmpty(commonCms.filePath)}">
                    <img th:src="@{${commonCms.filePath}}" alt="细则内容">
                </div>

                <!-- 无内容提示 -->
                <div class="no-content" th:if="${#strings.isEmpty(commonCms.content) and #strings.isEmpty(commonCms.filePath)}">
                    暂无内容
                </div>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer" />
<script th:inline="javascript">
    $(document).ready(function() {
        // 检查PDF是否加载成功
        $('.dangnei-pdf iframe').on('load', function() {
            try {
                // 尝试访问iframe内容，如果失败说明加载有问题
                var iframeDoc = this.contentDocument || this.contentWindow.document;
                // 如果iframe内容为空或出错，显示备用方案
            } catch (e) {
                // 跨域问题，无法检查内容，但不影响使用
            }
        }).on('error', function() {
            // iframe加载出错时的处理
            console.log('PDF加载出错');
        });
    });
</script>
</body>
</html>
